const path = require('path');
const resolve = dir => path.join(__dirname, dir);
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);

// 引入等比适配插件
const px2rem = require('postcss-px2rem')

// 配置基本大小
const postcss = px2rem({
  // 基准大小 baseSize，需要和rem.js中相同
  remUnit: 100
})

module.exports = {
  publicPath: './',
  assetsDir: 'static',
  productionSourceMap: false,
  outputDir: process.env.outputDir,
  devServer: {
    port: 5980,
    proxy: {
      "/apiBase": {
        target: "http://81.70.251.79:5800/",
        changeOrigin: true,
        pathRewrite: {
          "^/api": "",
        },
      },
      "/manage": {
        target: "http://81.70.251.79:5800/api/v1/icms/",
        changeOrigin: true,
        pathRewrite: {
          "^/manage": "",
        },
      },
    }
  },
  css: {
    loaderOptions: {
      sass: {

      },
      postcss: {
        plugins: [
          postcss

        ],
      },
    }
  },
  chainWebpack: config => {
    // 添加别名
    config.resolve.alias
      .set('@img', resolve('src/assets/images'))
      .set('@assets', resolve('src/assets'))
      .set('@public', resolve('public'))
    // 修复HMR
    config.resolve.symlinks(true);

    // set svg-sprite-loader
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      })
      .end();

  }
}